﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CWM.Client.Utils
{
    public partial class Speech
    {
        private static SpeechSynthesizer speak;

        private static void Init()
        {
            //创建语音实例
            speak = new SpeechSynthesizer();
            speak.Rate = int.Parse(ConfigurationManager.AppSettings["Speech.Rate"]); //设置语速,[-10,10]
            speak.Volume = 100; //设置音量,[0,100]
            try
            {
                string voice = ConfigurationManager.AppSettings["Speech.Voice"];
                speak.SelectVoice(voice);
            }
            catch 
            {

                //MessageBox.Show(Language.Get("Lang.SettingVoice"));
                return;
            }
       
        }

        //播放指定的字符串,这是异步朗读
        public static void SpeakAsync(string message)
        {
            if (speak == null)
            {
                Init();
            }
            speak.SpeakAsync(message);
        }
    }
}
